package com.softer.chengxin.sysscore.dao;

import com.softer.chengxin.common.domin.Page;
import com.softer.chengxin.sysscore.dao.provider.SysScoreTypeDaoProvider;
import com.softer.chengxin.sysscore.entity.SysScoreTypeDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zcz
 * @date 2018/12/12
 */
@Mapper
@Repository
public interface SysScoreTypeDao {
    /**
     * 查询评分类型列表,不带分页
     * @param scoreType   评分类型 0优良   1负面
     * @return 列表
     */
    @Select("SELECT id,score_name AS scoreName,score_type AS scoreType,max_score AS maxScore FROM score_type WHERE score_type = #{scoreType}")
    List<SysScoreTypeDTO> getScoreTypeListByScoreType(String scoreType);


    /**
     * 查询评分类型列表
     * @param page        页面实体
     * @param scoreTypeDTO 查询实体
     * @return 列表
     */
    @SelectProvider(type = SysScoreTypeDaoProvider.class, method = "getScoreTypeList")
    List<SysScoreTypeDTO> getScoreTypeList(@Param("page") Page page, @Param("scoreTypeDTO") SysScoreTypeDTO scoreTypeDTO);

    /**
     * 根据scoreType查询评分类型count
     * @param scoreTypeDTO        页面实体
     * @return count
     */
    @Select("SELECT COUNT(id) FROM score_type WHERE score_type = #{scoreType}")
    int getScoreTypeCount(SysScoreTypeDTO scoreTypeDTO);

    /**
     * 增加评分类型
     * @param s 详情数据
     * @return 增加结果
     */
    @Insert("INSERT INTO score_type(score_name,max_score,score_type,adder,add_time) VALUES(#{scoreName},#{maxScore},#{scoreType},#{adder},now())")
    int add(SysScoreTypeDTO s);

    /**
     * 修改评分类型
     * @param s 详情数据
     * @return 修改结果
     */
    @UpdateProvider(type = SysScoreTypeDaoProvider.class, method = "update")
    int update(SysScoreTypeDTO s);

    /**
     * 删除评分类型
     * @param id
     * @return 删除结果
     */
    @Delete("DELETE FROM score_type WHERE id = #{id}")
    int delete(String id);

    /**
     * 根据id查询评分类型
     * @param id
     * @return
     */
    @Select("SELECT id,score_name AS scoreName,max_score AS maxScore,score_type AS scoreType,adder,DATE_FORMAT(add_time, '%Y-%m-%d') AS ADDTIME FROM score_type  WHERE `id` = #{id}")
    SysScoreTypeDTO getScoreTypeById(String id);
}
